{% import 'admin/lib.html' as lib with context %}


{% macro render_field(form, field, kwargs={}, caller=None) %}
  {% set direct_error = h.is_field_error(field.errors) %}
  <td>

    <div>
      {{ field(**kwargs)|safe }}
    </div>
    {% if field.description %}
    <p class="help-block">{{ field.description }}</p>
    {% endif %}
    {% if direct_error %}
      <ul class="input-errors">
      {% for e in field.errors if e is string %}
        <li>{{ e }}</li>
      {% endfor %}
      </ul>
    {% endif %}

    {% if caller %}
      {{ caller(form, field, direct_error, kwargs) }}
    {% endif %}
  </td>
{% endmacro %}
{# Copier/coller de Lib #}
{% macro render_form_fields(form, form_opts=None) %}
    {% if form.hidden_tag is defined %}
        {{ form.hidden_tag() }}
    {% else %}
        {% if csrf_token %}
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
        {% endif %}
        {% for f in form if f.widget.input_type == 'hidden' %}
            {{ f }}
        {% endfor %}
    {% endif %}

    {% if form_opts and form_opts.form_rules %}
        {% for r in form_opts.form_rules %}
            {{ r(form, form_opts=form_opts) }}
        {% endfor %}
    {% else %}
        {% for f in form if f.widget.input_type != 'hidden' %}
          {% if form_opts %}
            {% set kwargs = form_opts.widget_args.get(f.name, {}) %}
          {% else %}
            {% set kwargs = {} %}
          {% endif %}
          {{ render_field(form, f, kwargs) }}
        {% endfor %}
    {% endif %}
{% endmacro %}

<div class="inline-form-field">
    <table >
        <tr>
  {{ render_form_fields(field.form, form_opts=form_opts) }}
        </tr>
    </table>
</div>
